#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e5 + 10, INF = 0x3f3f3f3f;

int root, idx;
struct node
{
    int ls, rs;
    int w, c, pri;
    int siz;
}tr[N];

int newnode(int w, int c)
{
    int p = ++idx;
    tr[p].ls = tr[p].rs = 0;
    tr[p].w = w, tr[p].c = c;
    tr[p].pri = rand();
    tr[p].siz = 1;
    return p;
}

void pushup(int x) { tr[x].siz = tr[tr[x].ls].siz + tr[tr[x].rs].siz + 1; }

void split1(int x, int k, int& l, int& r)
{
    if (x == 0) { l = r = 0; return; }
    if (tr[x].c <= k) {
        l = x;
        split1(tr[x].rs, k, tr[x].rs, r);
    } else {
        r = x;
        split1(tr[x].ls, k, l, tr[x].ls);
    }
    pushup(x);
}

void split2(int x, int k, int& l, int& r)
{
    if (x == 0) { l = r = 0; return; }
    if (tr[tr[x].ls].siz + 1 <= k) {
        l = x;
        split2(tr[x].rs, k - tr[tr[x].ls].siz - 1, tr[x].rs, r);
    } else {
        r = x;
        split2(tr[x].ls, k, l, tr[x].ls);
    }
    pushup(x);
}

int merge(int l, int r)
{
    if (l == 0 || r == 0) return l + r;
    if (tr[l].pri > tr[r].pri) {
        tr[l].rs = merge(tr[l].rs, r);
        pushup(l);
        return l;
    } else {
        tr[r].ls = merge(l, tr[r].ls);
        pushup(r);
        return r;
    }
}

void insert(int w, int c)
{
    int l, r, p;
    split1(root, c, l, r);split1(l, c - 1, l, p);
    if (p == 0) p = newnode(w, c);
    root = merge(merge(l, p), r);
}

void delmx() {
    int x;
    split2(root, tr[root].siz - 1, root, x);
}

void delmi() {
    int x;
    split2(root, 1, x, root);
}

pair<int, int> dfs(int x)
{
    if (x == 0) return { 0,0 };
    pair<int, int> tmp1 = dfs(tr[x].ls);
    pair<int, int> tmp2 = dfs(tr[x].rs);
    return { tmp1.first + tmp2.first + tr[x].w,tmp1.second + tmp2.second + tr[x].c };
}

void solve()
{
    int op, x, y;
    root = idx = 0;
    while (cin >> op, op != -1) {
        if (op == 1) {
            cin >> x >> y;
            insert(x, y);
        } else if (op == 2) {
            delmx();
        } else if (op == 3) {
            delmi();
        }
    }
    pair<int, int> ans = dfs(root);
    cout << ans.first << ' ' << ans.second;
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    srand(time(NULL));
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}